-
Notifications
You must be signed in to change notification settings - Fork 56
Add basic http client support #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add basic http client support #28
Conversation
Decided to build in auth, going to draft to test it |
Auth is tested and working |
@jcat4 can you rebase on main and resolve conflicts? seems to be largely the |
Thank you for your work on this, @jcat4. We're looking forward to seeing it merged. Is there an expected timeline for this? |
Sorry, lost track of this. I thought we wanted to go with the pluggable approach? If so, I can close this Or I can try to rework this to be closer to what y'all envisioned! |
@jcat4 @topherbullock Now that #27 is in, could we revisit this and get a client in there? 🙏 |
I'll make some time this week to knock this out |
e72bcfa
to
3a0b9b8
Compare
Spoke with @juharris, and we decided a pluggable approach would probably be better. The primary reason is it will allow folks to implement and pass their own custom transport layers (and open the door for other gems to add more, too!). The first step might be a bit manual (create your transport, create your client by passing your transport, send messages to your client), but we can iterate later with convenience wrappers that won't break existing code Overall, it seems like the safer bet. What we have is functional, but maybe not flexible enough for a public gem. Will begin work on this again next week when I have time, I think I can knock something out relatively quickly |
@@ -8,3 +8,6 @@ | |||
/spec/reports/ | |||
/tmp/ | |||
Gemfile.lock | |||
|
|||
# Mac stuff | |||
.DS_Store |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
@jcat4 Thanks for doing this! |
lib/mcp/client/http.rb
Outdated
module MCP | ||
module Client | ||
class Http | ||
DEFAULT_VERSION = "0.1.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what purpose this serves. I think I copied some other code in the app. If there are no strong feelings, I'm going to drop this and the version attr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dropped, pls let me know if this should be added back and why
# @note | ||
# The exact requirements for `input` are determined by the transport layer in use. | ||
# Consult the documentation for your transport (e.g., MCP::Client::HTTP) for details. | ||
def call_tool(tool:, input: nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could **kwargs
this is we want to let folks pass their own special stuff for custom transport layers, too
# Initializes a new MCP::Client instance. | ||
# | ||
# @param transport [Object] The transport object to use for communication with the server. | ||
# The transport should be a duck type that responds to both `#tools` and `#call_tool`. | ||
# This allows the client to list available tools and invoke tool calls via the transport. | ||
# | ||
# @example | ||
# transport = MCP::Client::HTTP.new(url: "http://localhost:3000") | ||
# client = MCP::Client.new(transport: transport) | ||
# | ||
# @note | ||
# The transport does not need to be a specific class, but must implement: | ||
# - #tools | ||
# - #call_tool(tool:, input:) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't see other YARD docs in this gem, but felt it might be useful to document ducktypes and whatnot. I want this to be easy to understand
Motivation and Context
Closes #3
Follow-up to #27
This adds the ability to build MCP clients with the ruby sdk. I've started with just a basic HTTP transport layer. We can add other things (i.e. streamable HTTP) later.
Per this comment, we've decided to go with a pluggable approach where:
Client
is initialized with a transport layer.tools
orcall_tool
)send_request
method to communicate with the serverFor simplicity, I'm just allowing custom headers to specify auth. I didn't want to build an abstraction around different auth types prematurely. I've made authentication the responsibility of the transport layer, since that's what is responsible for communication with the server.
How Has This Been Tested?
The local gem build has been tested in 2 different internal repositories and is working as expected so far.
Breaking Changes
Just the stuff from #27
Types of changes
Checklist
Additional context